package app.excel.cartoon.word;

import java.io.File;

import app.esb.common.DBExcutor;
import app.excel.cartoon.index.ExcelCartoonIndex;
import cn.lily.com.file.excel.io.ExcelWriter;

/**
 * 首字母动漫
 * @author JiaJ
 *
 */
public class ExcelCartoonWord {
	
	/**
	 * 文件路径
	 */
	private String filePath;
	
	/**
	 * Excel处理类
	 */
	private ExcelWriter excelWriter;
	
	public String getFilePath() {
		return filePath;
	}

	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}
	
	/**
	 * 导出数据
	 */
	public void export(){
		
		//初始化文件
		this.instFile();
		
		this.excelWriter = new ExcelWriter(this.filePath);		
		this.excelWriter.inst(100);
		
		//完成首页
		ExcelCartoonIndex.buildSheet(excelWriter);
		
		//数据分析
		ExcelWordData data = new ExcelWordData();	
		data.instData();
		data.excuteData();
		
		//
		String words = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		
		for(int i=0;i<words.length();i++){
			
			//当前Sheet
			String active = "";
			if(i == words.length()-1){
				active = words.substring(i);
			}else{
				active = words.substring(i,i+1);
			}
			
			//解析Sheet
			ExcelWordSheet sheet = new ExcelWordSheet();
			sheet.setSheetIdx(i+1);
			sheet.setSheetName(active);
			sheet.setData(data);
			
			sheet.writeSheet(this.excelWriter);
			
		}
		
		//写出
		this.excelWriter.write();
	}
	
	/**
	 * 初始化文件
	 */
	private void instFile(){
		File file = new File(this.filePath);
		if(file.exists()){
			file.delete();
		}
		System.out.println("初始化文件完成.........");
	}
	
	/**
	 * 释放
	 */
	public void free(){
		if(this.excelWriter != null){
			this.excelWriter.free();
		}
	}
	
	public static void main(String[] args) {
		
		DBExcutor.createEnv();
		
		ExcelCartoonWord excelWord = new ExcelCartoonWord();
		
		excelWord.setFilePath("D:/aa.xlsx");
		
		excelWord.export();
		
		excelWord.free();
		
	}


	
}
